package edu.njfu.activitybootmode

import android.app.Activity

/**
 * 定义一个单例对象，作为所有Activity的父类
 */
object ActivityController {
    //定义一个list，用户保存Activity
    private val activities=ArrayList<Activity>()

    /**
     *  向list中添加activity
     */
    fun addActivity( activity: Activity)=activities.add(activity)

    /**
     * 从list中删除activity
     */
    fun removeActivity(activity: Activity): Boolean = activities.remove(activity)

    /**
     * 循环方式终止list中的所有activity，并清空list
     */
    fun finishAll(){
        for(activity in activities){
            if(!activity.isFinishing){
                activity.finish()
            }
        }
        activities.clear()
    }

}